"""
    第三方微博登陆接口
"""
from urllib.parse import urlencode

from dashopt.settings import WEIBO_CONFIG


class OAuthWeiAPI:
    def __init__(self, app_key, app_secret, redirect_uri):
        self.app_key = app_key
        self.app_secret = app_secret
        self.redirect_uri = redirect_uri  # 回调地址

    def get_grant_url(self):
        """获取微博授权登陆页的url地址"""
        url = 'https://api.weibo.com/oauth2/authorize?'
        params = {
            "client_id": self.app_key,
            "redirect_uri": self.redirect_uri,
            "response_type": 'code'
        }
        return url + urlencode(params)


# config = {
#     "app_key": "2848177669",
#     "app_secret": "f29fa560ea090577173fe178cfe61e12",
#     "redirect_uri": "http://localhost:7000/dadashop/templates/callback.html",
# }
t = OAuthWeiAPI(**WEIBO_CONFIG)
